#include "connectionlist.h"


ConnectionList::ConnectionList() {
    read();
}


ConnectionList::~ConnectionList() {

}


void ConnectionList::write() {
    beginWriteArray("Profiles");
    for (int i; i < profileList.size(); i++) {
        setArrayIndex(i);
        setValue("ProfileName", profileList.at(i).profileName);
        setValue("ServerName", profileList[i].serverName);
        setValue("UserName", profileList[i].userName);
        setValue("Password", profileList[i].password);
        setValue("DatabaseName", profileList[i].databaseName);
    }
    endArray();
}


void ConnectionList::read() {
    clear();
    int lsz = beginReadArray("Profiles");

    for (int i; i < lsz; ++i) {
        setArrayIndex(i);
        ConnectionProfile cp = {
            value("ProfileName").toString(),
            value("ServerName").toString(),
            value("UserName").toString(),
            value("Password").toString(),
            value("DatabaseName").toString()
        };

        profileList.append(cp);
    }

    endArray();
}
